package com.gx.gxreader.activity

import android.support.v7.widget.GridLayoutManager
import android.view.View
import com.gx.gxreader.R
import com.gx.gxreader.adapter.CommentAdapter
import com.gx.gxreader.base.BaseActivity
import com.gx.gxreader.presenter.SearchPresenter
import com.gx.gxreader.view.SearchView
import kotlinx.android.synthetic.main.activity_search.*
import kotlinx.android.synthetic.main.rcv_item_hotsearch.view.*

/**
 * 搜索页面
 */
class SearchActivity : BaseActivity<SearchView, SearchPresenter>(), SearchView, View.OnClickListener {
    override fun createPresenter(): SearchPresenter = SearchPresenter()

    override fun getContentViewId(): Int = R.layout.activity_search

    override fun initViews() {
        rcvHotSearch.layoutManager = GridLayoutManager(this, 2)
        rcvHotSearch.adapter = CommentAdapter.Builder()
                .setDatas(getData())
                .setLayoutId(R.layout.rcv_item_hotsearch)
                .bindView(object : CommentAdapter.BindView{
                    override fun onBindView(viewHolder: CommentAdapter.MyViewHolder, data: Any?) {
                        val myData : String = data as String
                        viewHolder.itemView.tvNum.text = myData
                    }
                }).create()

        ivBack.setOnClickListener(this)
        ivSearchClearEdit.setOnClickListener(this)
    }

    override fun onClick(p0: View?) {
        when (p0?.id) {
            R.id.ivBack -> finish()
            R.id.ivSearchClearEdit -> etSearch.text = null
        }
    }

    /**
     * 制造假数据
     * 返回一个ArrayList<string> 的集合
     * */
    fun getData(): ArrayList<String> {
        val arrayList = ArrayList<String>()
        val list = listOf<String>("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
        //for循环
        for (k in list) {
            arrayList.add(k)
        }
        return arrayList
    }
}